<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>角色分配</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <%--<link rel="stylesheet" href="/js/compont/zTree_v3/css/demo.css" type="text/css">--%>
    <link rel="stylesheet" type="text/css" media="screen" href="/css/base/common.css" title="Version 1">
    <link href="/css/page/front/org_styles.css" rel="stylesheet" type="text/css" />
    <link href="/css/base/reset.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="/css/base/table_org.css"/>

    <link rel="stylesheet" href="/js/compont/zTree_v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
    <script type="text/javascript" src="/js/base/jquery.min.js"></script>
    <script type="text/javascript" src="/js/compont/jquery/jquery.mytab.js"></script>
    <script type="text/javascript" src="/js/compont/zTree_v3/js/jquery.ztree.core-3.5.min.js"></script>
    <script type="text/javascript" src="/js/compont/zTree_v3/js/jquery.ztree.excheck-3.5.min.js"></script>
    <script type="text/javascript">
        $(function () {
            var setting = {
                check: {
                    enable: true
                },
                data: {
                    simpleData: {
                        enable: true
                    }
                }
            };

            var zNodes =[
                    <c:forEach items="${sysUsers}" var="user">
                        { id:${user.id}, pId:0, name:'${user.loginName}', open:true
                            <c:if test="${user.roleHasThisUser}">
                                ,checked:true
                            </c:if>
                        },

                    </c:forEach>

            ];

            $.fn.zTree.init($("#users"), setting, zNodes);

            $("#submitBtn").click(function () {
                var zTree = $.fn.zTree.getZTreeObj("users");
                nodes = zTree.getCheckedNodes ();
                var addParam =  "";
                for (var i=0, l=nodes.length; i<l; i++) {
                    addParam +=nodes[i].id + ",";
                }

                $("#sysUsersIdsCsv").val(addParam);
                $("#submitForm").submit();
            });
        });
    </script>

</head>
<body>
<div class="row col-sm-offset-2">
    <form action="${controllerUrlPrefix}/setUsersForRole.do" id="submitForm" class="form-horizontal">
        <div class="form-group">
            <input type="hidden" name="sysUsersIdsCsv" id="sysUsersIdsCsv">
            <input type="hidden" name="roleId" value="${roleId}">
            <ul id="users" class="ztree"></ul>

        </div>

    </form>
    <div class="form-group">
        <input type="button" id="submitBtn" class="btn btn-primary btn-sm" value="提交"/>

    </div>
</div>
</body>
</html>
